﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace canyinguanlixitong
{
    public partial class 顾客开单 : Form
    {
        public 顾客开单()
        {
            InitializeComponent();
        }
        public int czno;
        DataSet ds = new DataSet();
        string constr = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void 顾客开单_Load(object sender, EventArgs e)
        {
            SqlConnection sqlcon = new SqlConnection(constr);
            string sql = @"SELECT  *
FROM      UserTpye";
            SqlDataAdapter adapter = new SqlDataAdapter(sql,sqlcon);
            adapter.Fill(ds,"userName");
            comboBox1.DataSource=ds.Tables["userName"];
            comboBox1.ValueMember = "userID";
            comboBox1.DisplayMember = "userName";
            adapter.Fill(ds, "userName1");
            comboBox2.DataSource = ds.Tables["userName1"];
            comboBox2.ValueMember = "userID";
            comboBox2.DisplayMember = "userName";
            string sql2 = @"SELECT  [Room type].fangName, [Room type].fangJia
FROM      [Room type] INNER JOIN
                   Roombiao ON [Room type].fangID = Roombiao.fangID where fangCz="+czno+"";
            sqlcon.Open();
            SqlCommand sqlcom = new SqlCommand(sql2,sqlcon);
            SqlDataReader reader = sqlcom.ExecuteReader();
            if (reader.Read())
            {
                label6.Text =Convert.ToString( reader["fangJia"]);
                label7.Text = Convert.ToString(reader["fangName"]);
            }
            sqlcon.Close();
            label5.Text =Convert.ToString( czno);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked==false)
            {
                string sql = "update [Table] set cz=1 where czID="+czno+"";
                SqlConnection sqlcon = new SqlConnection(constr);
                sqlcon.Open();
                SqlCommand sqlcom = new SqlCommand(sql, sqlcon);
                if (sqlcom.ExecuteNonQuery()>0)
                {
                    MessageBox.Show("开单成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("开单失败");
                    this.Close();
                }
                sqlcon.Close();
            }
            else
            {
                zengjiaxiaofei zen = new zengjiaxiaofei();
                zen.czno = czno;
                zen.Show();
                this.Close();
            }
        }
    }
}
